<!--管理员修改通知-->
<link rel="stylesheet" type="text/css" href="./css/amend.css" />

<!-- 模态框 -->
<div class="modal-dialog modal fade" id="fabu">
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal">&times;</button>
		</div>
		<div class="modal-body">
			<p>修改成功!点击确认返回到通知页</p>
		</div>
		<div class="modal-footer">
			<button id="ture1" type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
		</div>
	</div>
</div>

<div id="box">
	<h3 class="text-center">修改通知</h3>
	<div class="form-group">
		<label id="biaoti" class="text-left" for="exampleInputEmail1">标题</label>
		<input class="text-left" type="text" class="form-control" id="title" placeholder="在此输入标题">
	</div>
	<span id="span">权重</span>
	<select id="caidan">
		<option>1</option>
		<option>2</option>
		<option>3</option>
		<option>4</option>
		<option>5</option>
		<option>6</option>
		<option>7</option>
		<option>8</option>
		<option>9</option>
		<option>10</option>
	</select>
	<div id="amend_div">
		<script id="editor" type="text/plain" charset="utf-8" style="width: 100%; height: 360px;"></script>
	</div>
	<div class="text-center">
		<button type="button" class="btn btn-primary" id="xiugai1">修&nbsp;&nbsp;改</button>
		<button type="button" class="btn btn-default" id="fanhui1">返&nbsp;&nbsp;回</button>
	</div>
</div>

<script type="text/javascript" charset="utf-8">
	//实例化编辑器
	UE.delEditor('editor');
	//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	var ue = UE.getEditor('editor', {
		initialFrameWidth: '100%', //设置编辑器宽度
		scaleEnabled: true, //设置不自动调整高度
		//scaleEnabled {Boolean} [默认值：false]//是否可以拉伸长高，(设置true开启时，自动长高失效)
		toolbars: [
			['toggletool', 'fullscreen', 'source', '|', 'undo', 'redo', '|',
				'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript',
				'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|',
				'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|',
				'simpleupload', 'insertimage', '|', 'selectall', 'cleardoc'
			]
		]
	});
</script>

<script>
	// 页面跳转到通知页
	$('#ture1').click(function() {
		setTimeout(() => {
			$('.center').html('');
			$('.center').load('./messageamend.html');
		}, 300);
	})

	//弹窗
	$('#xiugai1').click(function() {
		$('#fabu').modal({
			keyboard: true,
			show: true
		})
	})

	//弹窗
	$('#fanhui1').click(function() {
		setTimeout(() => {
			$('.center').html('');
			$('.center').load('./messageamend.html');
		}, 300);
	})

	var flag = $.ajax({
		xhrFields: {
			withCredentials: true
		},
		type: "get",
		url: getFullURL("sel-inform"),
		dataType: 'json',
		data: {
			iid: $.session.get('iid')
		},
		success: function(data) {
			var i = data.inform.priority;
			$('#title').val(data.inform.title);
			$('#caidan').children("option").eq(i - 1).attr('selected', "selected");
			ue.addListener("ready", function() {
				ue.setContent(data.inform.content);
			});
		},
		error: function(err) {
			alert("请求异常，请重新登录！", function() {
				$(location).attr('href', './login.html');
			})
		}
	});

	$('#xiugai1').click(function() {
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: "POST",
			url: getFullURL("admin/update-inform"),
			dataType: 'json',
			data: {
				iid: $.session.get('iid'),
				Sid: "xiangsihu",
				title: $('#title').val(),
				content: UE.getEditor('editor').getContent(),
				priority: $("#caidan option:selected").text()
			},
			success: function(data) {
				if(data.status == 0) {
					console.log(1);
				}

			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	})
</script>